package com.pipi.mq.rocketmq.base.producer.config;

import com.pipi.mq.rocketmq.base.config.PropertiesConfig;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @Package com.pipi.mq.rocketmq.base
 * @author: 皮皮（pipi@maihaoche.com）
 * @date: 2020/4/18 2:44 PM
 */
@Configuration
@ComponentScan("com.pipi.mq.rocketmq.base.producer")
@PropertySource("classpath:application.properties")
public class ProducerConfig {

    @Bean
    public DefaultMQProducer getProducer() {
        DefaultMQProducer producer = new DefaultMQProducer(PropertiesConfig.producerGroup);
        producer.setNamesrvAddr(PropertiesConfig.nameServerAddress);
        try {
            producer.start();
        } catch (MQClientException e) {
            e.printStackTrace();
        }
        return producer;
    }

}
